﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;
namespace IFRS.DataAccess.DAL
{
    public class SPR_HPAndTFAddOn
    {
        public DataTable SEARCH_ALL(HPAndTFAddOn hPAndTFAddOn, Paging paging, bool IFRS_ALLBRANCH, string sIFRS_COST_CENTER, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));
                lstParams.Add(new SqlParameter("@isAllBranch", IFRS_ALLBRANCH));
                lstParams.Add(new SqlParameter("@sCostCenter", sIFRS_COST_CENTER));
                lstParams.Add(new SqlParameter("@TransactionDate", hPAndTFAddOn.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", hPAndTFAddOn.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", hPAndTFAddOn.AccountNo.AsDBValue()));
               
                dt = Utility.StoredProcDataTable("SPR_HPAndTFAddOn_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable SEARCH_BYID(int HPAndTFAddOnID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@HPAndTFAddOnID", HPAndTFAddOnID.AsDBValue()));
                dt = Utility.StoredProcDataTable("SPR_HPAndTFAddOn_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(HPAndTFAddOn hPAndTFAddOn)
        {

            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@HPAndTFAddOnID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@TransactionDate", hPAndTFAddOn.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", hPAndTFAddOn.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", hPAndTFAddOn.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@RefinanceDate", hPAndTFAddOn.RefinanceDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@MisPaymentDate", hPAndTFAddOn.MisPaymentDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@LoanObjectiveID", hPAndTFAddOn.LoanObjectiveID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ArrangementPurposeID", hPAndTFAddOn.ArrangementPurposeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreditLevelID", hPAndTFAddOn.CreditLevelID.AsDBValue()));
                lstParams.Add(new SqlParameter("@DoubtfulStatusID", hPAndTFAddOn.DoubtfulStatus.AsDBValue()));
                lstParams.Add(new SqlParameter("@OperationStatusID", hPAndTFAddOn.OperationStatus.AsDBValue()));
                lstParams.Add(new SqlParameter("@TDRTypeID", hPAndTFAddOn.TDRTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ChangeConditionID", hPAndTFAddOn.ChangeConditionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@OldAccountNo", hPAndTFAddOn.OldAccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@ReservedAmount", hPAndTFAddOn.ReservedAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@UnpaidInterest", hPAndTFAddOn.UnpaidInterest.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", hPAndTFAddOn.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedDate", hPAndTFAddOn.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", hPAndTFAddOn.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", hPAndTFAddOn.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", hPAndTFAddOn.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", hPAndTFAddOn.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", hPAndTFAddOn.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", hPAndTFAddOn.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", hPAndTFAddOn.UpdatedBranch.AsDBValue()));

                Utility.ExecuteStoredProc("SPR_HPAndTFAddOn_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(HPAndTFAddOn hPAndTFAddOn)
        {


            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@HPAndTFAddOnID", hPAndTFAddOn.HPAndTFAddOnID.AsDBValue()));
                lstParams.Add(new SqlParameter("@TransactionDate", hPAndTFAddOn.TransactionDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", hPAndTFAddOn.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@AccountNo", hPAndTFAddOn.AccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@RefinanceDate", hPAndTFAddOn.RefinanceDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@MisPaymentDate", hPAndTFAddOn.MisPaymentDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@LoanObjectiveID", hPAndTFAddOn.LoanObjectiveID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ArrangementPurposeID", hPAndTFAddOn.ArrangementPurposeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreditLevelID", hPAndTFAddOn.CreditLevelID.AsDBValue()));
                lstParams.Add(new SqlParameter("@DoubtfulStatusID", hPAndTFAddOn.DoubtfulStatus.AsDBValue()));
                lstParams.Add(new SqlParameter("@OperationStatusID", hPAndTFAddOn.OperationStatus.AsDBValue()));
                lstParams.Add(new SqlParameter("@TDRTypeID", hPAndTFAddOn.TDRTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@ChangeConditionID", hPAndTFAddOn.ChangeConditionID.AsDBValue()));
                lstParams.Add(new SqlParameter("@OldAccountNo", hPAndTFAddOn.OldAccountNo.AsDBValue()));
                lstParams.Add(new SqlParameter("@ReservedAmount", hPAndTFAddOn.ReservedAmount.AsDBValue()));
                lstParams.Add(new SqlParameter("@UnpaidInterest", hPAndTFAddOn.UnpaidInterest.AsDBValue()));
                lstParams.Add(new SqlParameter("@IsConfirmed", hPAndTFAddOn.IsConfirmed.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", hPAndTFAddOn.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", hPAndTFAddOn.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", hPAndTFAddOn.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", hPAndTFAddOn.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_HPAndTFAddOn_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(HPAndTFAddOn hPAndTFAddOn)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@HPAndTFAddOnID", hPAndTFAddOn.HPAndTFAddOnID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", hPAndTFAddOn.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", hPAndTFAddOn.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", hPAndTFAddOn.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", hPAndTFAddOn.UpdatedBranch.AsDBValue()));

                iNum = (int)Utility.ExecuteStoredProc("SPR_HPAndTFAddOn_DELETE", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
